﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Windows.Forms;

public partial class manage_OrderInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getinfo();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string orderid = Request.Params["orderid"].ToString();
        DataClassesDataContext db = new DataClassesDataContext();
        var result = from a in db.tb_OrderInfo
                     where a.OrderID == int.Parse(orderid)
                     select a;
        foreach (tb_OrderInfo info in result)
        {
            info.IsConfirm=this.CheckBox1.Checked;
            info.IsSend=this.CheckBox2.Checked;
            info.RealName = TextBox3.Text.ToString().Trim();
            info.Phone = TextBox4.Text.ToString().Trim();
            info.Address = TextBox5.Text.ToString().Trim();
        }
        db.SubmitChanges();
        Response.Write("<script>alert('修改成功！')</script>");
    }
    public void getinfo()
    {
        int all, price, num;

        string orderid = Request.Params["orderid"].ToString();
        string connstr = ConfigurationManager.AppSettings["sqlserver"];
        SqlConnection sqlconn = new SqlConnection(connstr);
        string sqlstr = "select * from tb_OrderInfo  where  OrderID='" + orderid + "'";
        SqlDataAdapter myadpt = new SqlDataAdapter(sqlstr, sqlconn);
        DataSet ds = new DataSet();
        sqlconn.Open();
        myadpt.Fill(ds, "orderinfo");
        num=int.Parse(ds.Tables["orderinfo"].Rows[0]["Number"].ToString());
        price = int.Parse(ds.Tables["orderinfo"].Rows[0]["HotPrice"].ToString());
        //yf = int.Parse(ds.Tables["orderinfo"].Rows[0]["ShipFee"].ToString());
        all=num *price;
        this.Label1.Text = ds.Tables["orderinfo"].Rows[0]["OrderID"].ToString();
        this.Label2.Text = ds.Tables["orderinfo"].Rows[0]["OrderDate"].ToString();
        this.Label4.Text = ds.Tables["orderinfo"].Rows[0]["BookID"].ToString();
        this.Label5.Text = ds.Tables["orderinfo"].Rows[0]["Number"].ToString();
        //this.Label6.Text = ds.Tables["orderinfo"].Rows[0]["ShipFee"].ToString() + "元";
        this.Label7.Text = ds.Tables["orderinfo"].Rows[0]["HotPrice"].ToString() + "元";
        this.Label8.Text = all.ToString() + "元";
        this.TextBox3.Text = ds.Tables["orderinfo"].Rows[0]["RealName"].ToString();
        this.TextBox4.Text = ds.Tables["orderinfo"].Rows[0]["Phone"].ToString();
        this.TextBox5.Text = ds.Tables["orderinfo"].Rows[0]["Address"].ToString();
        this.CheckBox1.Checked = bool.Parse(ds.Tables["orderinfo"].Rows[0]["IsConfirm"].ToString());
        this.CheckBox2.Checked = bool.Parse(ds.Tables["orderinfo"].Rows[0]["IsSend"].ToString());
        sqlconn.Close();
    }
    
}